<?php
  if(!defined("__ZBXE__")) exit();
  if($called_position != "before_display_content") return;

  if(Context::get('module') == 'admin' && $addon_info->admin == "N") return;
  if ($addon_info->admin == "Only" && Context::get('module') != 'admin')return; #관리자 출력여부

  $member = Context::get('logged_info');
  $module = &getModel('module');
  $point = &getModel('point');
  $pointconfig = $module->getModuleConfig('point'); #각종 정보 담아오기

  if ($addon_info->cut){
    $title1 = explode($addon_info->cut, $addon_info->title1);
    $title1 = $title1[mt_rand(0,(count($title1) - 1))];
    $title2 = explode($addon_info->cut, $addon_info->title2);
    $title2 = $title2[mt_rand(0,(count($title2) - 1))];
  }else{
    $title1 = $addon_info->title1;
    $title2 = $addon_info->title2;
  } #타이틀1과 타이틀2를 변수에 담기

	if(Context::get('document_srl')!='') {
		// document 모듈의 model
		$oDocumentModel = &getModel('document');
		$oDocument = $oDocumentModel->getDocument(Context::get('document_srl'));
		$titleb = $oDocument->getTitleText();
	}else {
		$titleb = Context::getBrowserTitle();
	}

  $title1 = str_replace("%id%", $member->user_id, $title1);
  $title2 = str_replace("%id%", $member->user_id, $title2);
  $title1 = str_replace("%nick%", $member->nick_name, $title1);
  $title2 = str_replace("%nick%", $member->nick_name, $title2);
  $title1 = str_replace("%name%", $member->user_name, $title1);
  $title2 = str_replace("%name%", $member->user_name, $title2);
  $title1 = str_replace("%point%", $point->getPoint(abs($member->member_srl)), $title1);
  $title2 = str_replace("%point%", $point->getPoint(abs($member->member_srl)), $title2);
  $title1 = str_replace("%level%", $point->getLevel(($point->getPoint(abs($member->member_srl))), $pointconfig->level_step), $title1);
  $title2 = str_replace("%level%", $point->getLevel(($point->getPoint(abs($member->member_srl))), $pointconfig->level_step), $title2); #치환자

  switch ($addon_info->type){
    case "0": $title = $title1; break;
    case "1": $title = $title1 . " " . $titleb; break;
    case "2": $title = $titleb . " " . $title2; break;
    default: $title = $title1 . " " . $titleb . " " . $title2;
  } #타이틀 가공

  if ($addon_info->member == "Y" && !$member->user_id) return;
  if ($addon_info->member == "N" && $member->user_id) return;
  if ($addon_info->member == "Y1N2" && $member->user_id) $title = $title1;
  if ($addon_info->member == "Y1N2" && !$member->user_id) $title = $title2; #맴버만적용

  if ($addon_info->tag == "Y"){$title = strip_tags($title);}
  elseif ($addon_info->tag == "ltgt"){$title = htmlspecialchars($title);} #태그제거

  Context::setBrowserTitle($title); #적용
?>